//
//  NXNinthStepViewController.m
//  BiologyLibrary
//
//  Created by milo on 16/7/5.
//  Copyright © 2016年 youxh. All rights reserved.
//

#import "NXNinthStepViewController.h"
#import "NXTenthViewController.h"
#import "ZLTenthStepViewController.h"
@interface NXNinthStepViewController ()

@end

@implementation NXNinthStepViewController
#define LABELTAG   1000000
#define BTNTAG   2000000
static const NSString * KEY_STEP  = @"step9";
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
}
-(void)initData
{
    _shiguanarr=[[NSMutableArray alloc] init];
    for (Record *oneRecord in self.NewRecordArray) {
        NSMutableArray*onequestArr=[[NSMutableArray alloc]init];
       
        for (int i = 0; i < 6; i ++)
        {
            NSString*namestr=@"";
            if (i==0) {
                namestr=@"FT-1";
            }if (i==1) {
                namestr=@"FT-2";

            }if (i==2) {
                namestr=@"FT-3";

            }if (i==3) {
                namestr=@"FN-1";

            }if (i==4) {
                namestr=@"FN-2";

            }if (i==5) {
                namestr=@"FN-3";

            }
            NSMutableDictionary *questionMDict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
                                                  namestr, @"name",
                                                  @"500（默认）", @"tiji",
                                                  @"√", KEY_RECORD_ANSWER, nil];
            [onequestArr addObject:questionMDict];
            }
        
        [_shiguanarr addObject:onequestArr];
        
    }
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self initData];

    // Do any additional setup after loading the view.
    // 创建一个自定义的按钮，并添加到导航条左侧。
    UIButton *btnNaviLeft = [CustomNaviBarView createImgNaviBarBtnByImgNormal:@"bar_left_image"
                                                                 imgHighlight:@"bar_left_image_f"
                                                                       target:self
                                                                       action:@selector(btnNaviLeftClick)];
    [self setNaviBarLeftBtn:btnNaviLeft];

    NSLog(@"setp9 record === %@", self.NewRecordArray.firstObject.getDetailDict);
    [self setNaviBarTitle:self.NewRecordArray.firstObject.name];
    _maintableview=[[UITableView alloc]initWithFrame:CGRectMake(10, 64, fWidth_Current-20, fHeight_Current-64-50)];
    _maintableview.backgroundColor = [UIColor clearColor];
    _maintableview.separatorStyle = UITableViewCellSeparatorStyleNone;
    _maintableview.dataSource = self;
    _maintableview.delegate = self;
    _maintableview.showsVerticalScrollIndicator=NO;
    [self.view addSubview:_maintableview];
    weizhiarr=[NSArray arrayWithObjects:@"A1",@"A2",@"A3",@"A4",@"A5",@"A6",@"A7",@"A8",@"A9",@"B1",@"B2",@"B3",@"B4",@"B5",@"B6",@"B7",@"B8",@"B9",@"C1",@"C2",@"C3",@"C4",@"C5",@"C6",@"C7",@"C8",@"C9",@"D1",@"D2",@"D3",@"D4",@"D5",@"D6",@"D7",@"D8",@"D9",@"E1",@"E2",@"E3",@"E4",@"E5",@"E6",@"E7",@"E8",@"E9",@"F1",@"F2",@"F3",@"F4",@"F5",@"F6",@"F7",@"F8",@"F9",@"G1",@"G2",@"G3",@"G4",@"G5",@"G6",@"G7",@"G8",@"G9",@"H1",@"H2",@"H3",@"H4",@"H5",@"H6",@"H7",@"H8",@"H9",@"I1",@"I2",@"I3",@"I4",@"I5",@"I6",@"I7",@"I8",@"I9", nil];
    
    UIImageView*buttomview=[[UIImageView alloc]initWithFrame:CGRectMake(0, fHeight_Current-50, fWidth_Current, 50)];
    buttomview.backgroundColor=[UIColor colorWithRed:0.16 green:0.19 blue:0.24 alpha:1.0];
    [self.view addSubview:buttomview];
    UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, fWidth_Current, 50)];
    label.backgroundColor=[UIColor clearColor];
    label.textAlignment=1;
    label.font=[UIFont systemFontOfSize:14];
    label.textColor=[UIColor lightGrayColor];
    label.text= [NSString stringWithFormat:@"当下是第%ld/%ld步",
                 (long)self.NewRecordArray.firstObject.savedStepCount + 1, (long)self.NewRecordArray.firstObject.allStepCount];
    [buttomview addSubview:label];
    
    if ([[self.NewRecordArray.firstObject getDetailDict] objectForKey:KEY_STEP] &&
        [[[self.NewRecordArray.firstObject getDetailDict] objectForKey:KEY_STEP] count] > 0 &&
        [[[[self.NewRecordArray.firstObject getDetailDict] objectForKey:KEY_STEP] objectAtIndex:0] objectForKey:KEY_RECORD_ANSWER]) {
        
        savetime = [[[[self.NewRecordArray.firstObject getDetailDict] objectForKey:KEY_STEP] objectAtIndex:0] objectForKey:KEY_RECORD_ANSWER];
    }else{
        savetime = @"";
    }
    
    areaarr=[[NSMutableArray alloc]init];
    [areaarr addObjectsFromArray:[APPUserDict objectForKey:@"ydareaarr"]];
    answerArr=[[NSMutableArray alloc]init];
    for (Record *nowRecord in self.NewRecordArray) {
        NSMutableArray*newarr=[[NSMutableArray alloc]init];
        NSString*answer=@"请选择";
        NSInteger index=[self.NewRecordArray indexOfObject:nowRecord];
        NSArray*oneArr=[_shiguanarr objectAtIndex:index];
        for (int i=0; i<oneArr.count; i++) {
            
            if ([[nowRecord getDetailDict] objectForKey:KEY_STEP] &&
                [[[nowRecord getDetailDict] objectForKey:KEY_STEP] count] > 1+i &&
                [[[[nowRecord getDetailDict] objectForKey:KEY_STEP] objectAtIndex:1+i] objectForKey:KEY_RECORD_ANSWER]) {
                answer = [[[[nowRecord getDetailDict] objectForKey:KEY_STEP] objectAtIndex:1+i] objectForKey:KEY_RECORD_ANSWER];
            }
            [newarr addObject:answer];
        }
        [answerArr addObject:newarr];
    }

    
}
#pragma mark - UITableViewDataSource

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
   
    return 1;
    
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 4+self.NewRecordArray.count;//返回标题数组中元素的个数来确定分区的个数
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.section==0) {
        NSString*titlestr=@"9.1、技术员将样本送回生物样本库，并入库。";
        
        CGSize hight=[TGCDataCenter getContentSize:titlestr WithMaxSize:CGSizeMake(fWidth_Current-40, 1000) Font:[UIFont systemFontOfSize:17] LineBreakMode:NSLineBreakByWordWrapping];
        
        return 40+hight.height;
        
    }else if(indexPath.section==1+self.NewRecordArray.count){
        return 50;
    }else if(indexPath.section==2+self.NewRecordArray.count){
       
        NSString*titlestr=@"8.2、存放入位置的日期和时间";
        CGSize hight=[TGCDataCenter getContentSize:titlestr WithMaxSize:CGSizeMake(fWidth_Current-40, 1000) Font:[UIFont systemFontOfSize:17] LineBreakMode:NSLineBreakByWordWrapping];
        return 40+hight.height+60;
        
    }else if(indexPath.section==3+self.NewRecordArray.count){
        return 50;
    }else{
        NSArray*oneArr=[_shiguanarr objectAtIndex:indexPath.section-1];
        return 40+40*oneArr.count+30;
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 10;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView*headview=[[UIView alloc]initWithFrame:CGRectMake(0, 0, fWidth_Current, 18)];
    headview.backgroundColor=[UIColor clearColor];
    return headview;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *strIdentifier = @"strIdentifier";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:strIdentifier];
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
                                  reuseIdentifier:strIdentifier];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.backgroundColor=[UIColor colorWithRed:0.16 green:0.19 blue:0.24 alpha:1.0];
    if (indexPath.section==0) {
        NSString*titlestr=@"9.1、技术员将样本送回生物样本库，并入库。";
        if (self.NewRecordArray.firstObject.type==2) {
            titlestr=@"8.1、技术员将样本送回生物样本库，并入库。";
            
        }
        CGSize hight=[TGCDataCenter getContentSize:titlestr WithMaxSize:CGSizeMake(fWidth_Current-40, 1000) Font:[UIFont systemFontOfSize:17] LineBreakMode:NSLineBreakByWordWrapping];
        UILabel *titlelab=[[UILabel alloc]initWithFrame:CGRectMake(10, 20, fWidth_Current-40, hight.height)];
        titlelab.textColor=[UIColor whiteColor];
        titlelab.backgroundColor=[UIColor clearColor];
        titlelab.text=titlestr;
        titlelab.numberOfLines=0;
        titlelab.font=[UIFont systemFontOfSize:17];
        [cell addSubview:titlelab];
    }else if(indexPath.section==3+self.NewRecordArray.count){
        cell.backgroundColor=[UIColor clearColor];
        
        if (self.fromtype && [self.fromtype isEqualToString:@"search"]) {
            
            UIButton *btn2=[[UIButton alloc]initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 50)];
            btn2.backgroundColor=[UIColor colorWithRed:0.22 green:0.57 blue:0.91 alpha:1.0];
            btn2.layer.cornerRadius=5;
            [btn2 setTitle:@"下一步" forState:UIControlStateNormal];
            btn2.clipsToBounds=YES;
            [btn2 addTarget:self action:@selector(nextStepClick) forControlEvents:UIControlEventTouchUpInside];
            [cell addSubview:btn2];
        }else{
            
            UIButton *btn1=[[UIButton alloc]initWithFrame:CGRectMake(0, 0, (fWidth_Current-30)/2, 50)];
            btn1.backgroundColor=[UIColor colorWithRed:0.16 green:0.19 blue:0.24 alpha:1.0];
            btn1.layer.cornerRadius=5;
            [btn1 setTitle:@"取消" forState:UIControlStateNormal];
            btn1.clipsToBounds=YES;
            [btn1 addTarget:self action:@selector(cancelclick) forControlEvents:UIControlEventTouchUpInside];
            [cell addSubview:btn1];
            UIButton *btn2=[[UIButton alloc]initWithFrame:CGRectMake((fWidth_Current-30)/2+10, 0, (fWidth_Current-30)/2, 50)];
            btn2.backgroundColor=[UIColor colorWithRed:0.22 green:0.57 blue:0.91 alpha:1.0];
            btn2.layer.cornerRadius=5;
            [btn2 setTitle:@"保存" forState:UIControlStateNormal];
            btn2.clipsToBounds=YES;
            [btn2 addTarget:self action:@selector(saveClick) forControlEvents:UIControlEventTouchUpInside];
            [cell addSubview:btn2];
        }
    }else if(indexPath.section==2+self.NewRecordArray.count){
        NSString*titlestr;

        if (self.NewRecordArray.firstObject.type== TYPE_RECORD_SHITIZHONGNIU) {
            titlestr=@"8.2、存放入位置的日期和时间";
            
        }else{
            titlestr=@"9.2、放入液氮罐的日期和时间";
            
        }
        CGSize hight=[TGCDataCenter getContentSize:titlestr WithMaxSize:CGSizeMake(fWidth_Current-40, 1000) Font:[UIFont systemFontOfSize:17] LineBreakMode:NSLineBreakByWordWrapping];
        UILabel *titlelab = [[UILabel alloc]initWithFrame:
                             CGRectMake(10, 20, fWidth_Current - 40, hight.height)];
        titlelab.textColor=[UIColor whiteColor];
        titlelab.backgroundColor=[UIColor clearColor];
        titlelab.numberOfLines=0;
        [cell addSubview:titlelab];
        titlelab.text=titlestr;
        UIImageView*lineview=[[UIImageView alloc]initWithFrame:CGRectMake(0, hight.height+40, fWidth_Current-20, 1)];
        lineview.backgroundColor=[UIColor colorWithRed:0.91 green:0.91 blue:0.91 alpha:0.3];
        [cell addSubview:lineview];
        if (datelabel==nil) {
            datelabel = [[UILabel alloc]initWithFrame:
                         CGRectMake(10, hight.height+40, tableView.frame.size.width - 40, 60)];
        }
        
        datelabel.backgroundColor = [UIColor clearColor];
        datelabel.textColor = [UIColor colorWithRed:0.22 green:0.57 blue:0.91 alpha:1.0];
        datelabel.text=savetime;
        [cell addSubview:datelabel];
        UIButton *btn1=[[UIButton alloc]initWithFrame:CGRectMake(fWidth_Current-20-60, hight.height+40+18, 50, 25)];
        btn1.backgroundColor=[UIColor colorWithRed:0.22 green:0.57 blue:0.91 alpha:1.0];
        btn1.layer.cornerRadius=10;
        [btn1 setTitle:@"选择" forState:UIControlStateNormal];
        [btn1 addTarget:self action:@selector(reloadtime) forControlEvents:UIControlEventTouchUpInside];
        btn1.titleLabel.font=[UIFont systemFontOfSize:11];
        btn1.clipsToBounds=YES;
        btn1.hidden=YES;
        [cell addSubview:btn1];
    }else if(indexPath.section==1+self.NewRecordArray.count){
        cell.backgroundColor=[UIColor clearColor];
        UIButton *btn1=[[UIButton alloc]initWithFrame:CGRectMake(0, 0, (fWidth_Current-20), 50)];
        btn1.backgroundColor=[UIColor colorWithRed:0.22 green:0.57 blue:0.91 alpha:1.0];
        btn1.layer.cornerRadius=5;
        if (self.NewRecordArray.firstObject.type== TYPE_RECORD_SHITIZHONGNIU) {
            [btn1 setTitle:@"放入储存位置" forState:UIControlStateNormal];
            
        }else{
            [btn1 setTitle:@"放入液氮罐" forState:UIControlStateNormal];
            
        }
        [btn1 addTarget:self action:@selector(reloadtime) forControlEvents:UIControlEventTouchUpInside];
        
        btn1.clipsToBounds=YES;
        [cell addSubview:btn1];
        
        if (self.fromtype && [self.fromtype isEqualToString:@"search"]) {
            btn1.hidden = YES;
        }else{
            btn1.hidden = NO;
        }
    }else{
        Record*nowrecord=[self.NewRecordArray objectAtIndex:indexPath.section-1];
        UILabel*recordNameLab=[[UILabel alloc]initWithFrame:CGRectMake(10, 5, fWidth_Current, 30)];
        recordNameLab.backgroundColor=[UIColor clearColor];
        recordNameLab.textColor=[UIColor whiteColor];
        recordNameLab.font=[UIFont systemFontOfSize:16];
        recordNameLab.text=[NSString stringWithFormat:@"样本号：%@",nowrecord.recordId];
        [cell addSubview:recordNameLab];
        NSArray*oneArr=[_shiguanarr objectAtIndex:indexPath.section-1];
        NSArray*oneanswerArr=[answerArr objectAtIndex:indexPath.section-1];
        for (int i=0; i<oneArr.count; i++) {
            UILabel*titlelab=[[UILabel alloc]initWithFrame:CGRectMake(0,40+i*40 , 80, 40)];
            titlelab.textColor=[UIColor lightGrayColor];
            titlelab.font=[UIFont systemFontOfSize:16];
            titlelab.backgroundColor=[UIColor clearColor];
            titlelab.textAlignment=1;
            [cell addSubview:titlelab];
            UIImageView*lineview=[[UIImageView alloc]initWithFrame:CGRectMake(0, 40+40+i*40, fWidth_Current-20, 0.5)];
            lineview.backgroundColor=[UIColor colorWithRed:0.91 green:0.91 blue:0.91 alpha:0.3];
            [cell addSubview:lineview];
            
            UILabel*titlelab2=[[UILabel alloc]initWithFrame:CGRectMake(80,40+i*40 , fWidth_Current-20-20-80-50, 40)];
            titlelab2.textColor=[UIColor lightGrayColor];
            titlelab2.font=[UIFont systemFontOfSize:16];
            titlelab2.textAlignment=1;
            titlelab2.backgroundColor=[UIColor clearColor];
            [cell addSubview:titlelab2];
            MiloBtn *btn1=[[MiloBtn alloc]initWithFrame:CGRectMake(fWidth_Current-20-60, 40+i*40+8, 50, 25)];
            btn1.backgroundColor=[UIColor colorWithRed:0.22 green:0.57 blue:0.91 alpha:1.0];
            btn1.layer.cornerRadius=10;
            [btn1 setTitle:@"选址" forState:UIControlStateNormal];
            [btn1 addTarget:self action:@selector(setarea:) forControlEvents:UIControlEventTouchUpInside];
            btn1.titleLabel.font=[UIFont systemFontOfSize:11];
            btn1.clipsToBounds=YES;
            [cell addSubview:btn1];
            if (self.fromtype && [self.fromtype isEqualToString:@"search"]) {
                btn1.hidden = YES;
            }else{
                btn1.hidden = NO;
            }
            NSDictionary*dic=[oneArr objectAtIndex:i];
            titlelab.text=[NSString stringWithFormat:@"%@",[dic objectForKey:@"name"]];
            titlelab2.tag=LABELTAG+i;
            btn1.tag=BTNTAG+i;
            btn1.subtag=indexPath.section-1;
            titlelab2.text = [oneanswerArr objectAtIndex:i];
        }
        
        UIImageView*lineview=[[UIImageView alloc]initWithFrame:CGRectMake(0, 40, fWidth_Current-20, 0.5)];
        lineview.backgroundColor=[UIColor colorWithRed:0.91 green:0.91 blue:0.91 alpha:0.3];
        UIImageView*lineview2=[[UIImageView alloc]initWithFrame:CGRectMake(80, 40, 0.5, 40*oneArr.count)];
        lineview2.backgroundColor=[UIColor colorWithRed:0.91 green:0.91 blue:0.91 alpha:0.3];
        [cell addSubview:lineview2];
        [cell addSubview:lineview];
        
        UILabel*tishilab=[[UILabel alloc]initWithFrame:CGRectMake(10, 40+40*oneArr.count, fWidth_Current-60, 30)];
        tishilab.text=@"自生物样本库软件获取储存位置，具体信息如下";
        tishilab.textColor=[UIColor grayColor];
        tishilab.backgroundColor=[UIColor clearColor];
        tishilab.font=[UIFont systemFontOfSize:12];
        [cell addSubview:tishilab];
    }
    
    return cell;
   
}
-(void)btnNaviLeftClick{
    
    
    if (self.NewRecordArray.firstObject.recordStatus==STATUS_RECORD_SAVED) {
        UIViewController*miloViewControl=(UIViewController *)[[self.navigationController viewControllers]objectAtIndex:1];
        [self.navigationController popToViewController:miloViewControl animated:YES];
        
    }else{
        [self.navigationController popViewControllerAnimated:YES];
    }
}
-(void)setarea:(MiloBtn *)sender{
    NSString*str=[@"" GetCurrntNet];
    if ([str isEqualToString:@"no"]) {
        [self.view makeToast:@"请连接网络获取存放位置！"];
        
        return;
    }
    
    NSLog(@"QWEQWE%@",[APPDataCenter getusedaddressarr:@"N1-PNA11-1-1-"]);

    NSLog(@"%@",[APPDataCenter getusedaddressArray]);
    nowselectindex=sender.tag;
    nowrow=sender.subtag;
    SelectAddressViewController*SelectAddressVC=[[SelectAddressViewController alloc]init];
    SelectAddressVC.strFOrN=@"N";
    SelectAddressVC.delegate=self;
    [self presentViewController:SelectAddressVC animated:YES completion:nil];
    

}
-(void)didSelectAddressFinished:(SelectAddressViewController *)selectAddressViewController withAddress:(NSString *)addressStr{
    
    if ([[APPDataCenter getusedaddressArray]containsObject:addressStr]) {
        [self.view makeToast:@"抱歉，该位置已经被您占用，请重新选择" position:@"center"];
        
        return;
    }
    NSString*addressstr0=[addressStr substringToIndex:[addressStr length]-2];
    
    NSString*addressstr=[addressStr substringFromIndex:[addressStr length]-2];
    long ii=0;
    ii=[weizhiarr indexOfObject:addressstr];
    NSArray*oneArr=[_shiguanarr objectAtIndex:nowrow];
    NSMutableArray*oneanswerArr=[answerArr objectAtIndex:nowrow];
    for (long i=nowselectindex-BTNTAG; i<oneArr.count; i++) {
        
        if (ii<=80) {
            NSString*answer=[oneanswerArr objectAtIndex:i];
            if(answer == nil || [answer isEqualToString:@"请选择"]){
                
            }else{
                [APPDataCenter removeusedaddressArray:answer];
            }
            
            for(long p=ii;p<=80;){
                NSString*nowareastr1=[NSString stringWithFormat:@"%@%@",addressstr0,[weizhiarr objectAtIndex:p]];
                
                if ([[APPDataCenter getusedaddressArray]containsObject:nowareastr1]) {
                    ii++;
                    p++;
                    
                }else{
                    answer=[NSString stringWithFormat:@"%@%@",addressstr0,[weizhiarr objectAtIndex:ii]];
                    [APPDataCenter addusedaddressArray:answer];
                    ii++;
                    break;
                }
            }
            
            [oneanswerArr replaceObjectAtIndex:i withObject:answer];
            
        }
    }
    [answerArr replaceObjectAtIndex:nowrow withObject:oneanswerArr];
    [_maintableview reloadData];
    [self creatDetailDict];
    

}


-(void)saveClick{
    if(datelabel.text == nil || [datelabel.text isEqualToString:@""]){
        [self.view makeToast:@"请置入存放的日期和时间！"];
        return;
    }
   
    [self creatDetailDict];
//    self.record.savedStepCount = self.record.savedStepCount + 1;
//    dispatch_async(dispatch_get_global_queue(0, 0), ^{
//        [self.record update];
//    });
    if (self.NewRecordArray.firstObject.type==2) {
        ZLTenthStepViewController*ZLTenthStepVC = [[ZLTenthStepViewController alloc] init];
        ZLTenthStepVC.NewRecordArray = self.NewRecordArray;
        [self.navigationController pushViewController:ZLTenthStepVC animated:YES];
    }else{
        NXTenthViewController *NXTenthStepVC = [[NXTenthViewController alloc] init];
        NXTenthStepVC.NewRecordArray = self.NewRecordArray;
        [self.navigationController pushViewController:NXTenthStepVC animated:YES];
    }
  
}
-(void)reloadtime{
    NSDate *currentDate = [NSDate date];//获取当前时间，日期
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"YYYY-MM-dd hh:mm"];
    NSString *dateString = [dateFormatter stringFromDate:currentDate];
    savetime=dateString;
    datelabel.text=savetime;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void)creatDetailDict{
    
    NSDictionary *questionDict = [NSDictionary dictionaryWithObjectsAndKeys:
                                   @"9.2、存放入液氮罐的日期和时间", KEY_RECORD_QUESTION,
                                   TYPE_QUESTION_DEFAULT, KEY_RECORD_TYPE,
                                   datelabel.text, KEY_RECORD_ANSWER, nil];
    
    for (Record *oneRecord in self.NewRecordArray) {
        NSMutableArray *qustionArr = [NSMutableArray arrayWithObjects:questionDict, nil];
        
        NSInteger index =[self.NewRecordArray indexOfObject:oneRecord];
        NSArray *oneAnswerarr=[answerArr objectAtIndex:index];
        
        for (int i=0; i<oneAnswerarr.count; i++) {
            NSString*numstr=[NSString stringWithFormat:@"%d",i+1];
            NSString*answer=[oneAnswerarr objectAtIndex:i];
            NSDictionary *questionDict1 = [NSDictionary dictionaryWithObjectsAndKeys:
                                           numstr, KEY_RECORD_QUESTION,
                                           TYPE_QUESTION_DEFAULT, KEY_RECORD_TYPE,
                                           answer, KEY_RECORD_ANSWER, nil];
            [qustionArr addObject:questionDict1];
        }
        NSMutableDictionary *tempDict = [oneRecord getDetailDict];
        [tempDict setObject:qustionArr forKey:KEY_STEP];
        [oneRecord setDetailDict:tempDict];
        oneRecord.recordDetail = [tempDict JSONString];
        oneRecord.savedStepCount = self.NewRecordArray.firstObject.savedStepCount + 1;
        dispatch_async(dispatch_get_global_queue(0, 0), ^{
            [oneRecord update];
        });
    }
   
}
-(void)cancelclick{
    UIViewController*miloViewControl=(UIViewController *)[[self.navigationController viewControllers]objectAtIndex:1];
    [self.navigationController popToViewController:miloViewControl animated:YES];
}

-(void)nextStepClick{
    
    self.NewRecordArray.firstObject.savedStepCount = self.NewRecordArray.firstObject.savedStepCount + 1;
    if (self.NewRecordArray.firstObject.type==2) {
        ZLTenthStepViewController*ZLTenthStepVC = [[ZLTenthStepViewController alloc] init];
        ZLTenthStepVC.NewRecordArray = self.NewRecordArray;
        ZLTenthStepVC.fromtype = @"search";
        [self.navigationController pushViewController:ZLTenthStepVC animated:YES];
    }else{
        NXTenthViewController *NXTenthStepVC = [[NXTenthViewController alloc] init];
        NXTenthStepVC.NewRecordArray = self.NewRecordArray;
        NXTenthStepVC.fromtype = @"search";
        [self.navigationController pushViewController:NXTenthStepVC animated:YES];
    }
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
